package ltd.flyweight.liquibasehelper;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ltd.flyweight.liquibasehelper.func.service.ILiquibaseHelperService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;


@Slf4j
@Getter
@RequiredArgsConstructor
@SpringBootApplication
public class LiquibaseHelperApplication implements ApplicationListener<ContextClosedEvent>, ApplicationRunner, Runnable {

    private final ILiquibaseHelperService liquibaseHelperService;

    public static void main(String[] args) {

        SpringApplication.run(LiquibaseHelperApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        run();
    }

    @Override
    public void run() {
        liquibaseHelperService.run();
    }

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        log.info("程序执行完成...");
    }
}
